package cn.tyoui.ssm.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.tyoui.ssm.exception.CustomException;
import cn.tyoui.ssm.mapper.IUserMapper;
import cn.tyoui.ssm.mapper.ItemsMapper;
import cn.tyoui.ssm.po.Items;
import cn.tyoui.ssm.po.ItemsCustom;
import cn.tyoui.ssm.po.UserCustom;
import cn.tyoui.ssm.service.interFace.ItemsService;

@Service
public class ItemsServiceImpl implements ItemsService {

	@Autowired
	private IUserMapper userMapper;

	@Autowired
	private ItemsMapper itemsMapper;

	@Override
	public List<UserCustom> findUserNameAll(UserCustom userQueryVo)
			throws Exception {
		return userMapper.findUserNameAll(userQueryVo);
	}

	@Override
	public List<ItemsCustom> findItemsList(ItemsCustom itemsCustom)
			throws Exception {
		return userMapper.findItemsList(itemsCustom);
	}

	@Override
	public ItemsCustom findItemsById(Integer id) throws Exception {
		Items items = itemsMapper.selectByPrimaryKey(id);
		ItemsCustom itemsCustom = null;
		if (items != null) {
			itemsCustom = new ItemsCustom();
			BeanUtils.copyProperties(items, itemsCustom);
		}else
			throw new CustomException("未知错误");
		return itemsCustom;
	}

	@Override
	public void updateItems(Integer id, ItemsCustom itemsCustom)
			throws Exception {
		itemsCustom.setId(id);
		itemsMapper.updateByPrimaryKeyWithBLOBs(itemsCustom);
	}

}
